package Servlet.login_register;

import Dao.UserDao;
import Utils.mybatisUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;

public class registerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username="";
        String password="";
        String user="";
        username=request.getParameter("username");
        password=request.getParameter("password");
        user=request.getParameter("user");
        SqlSession session= mybatisUtils.getSqlSession();
        UserDao dao=session.getMapper(UserDao.class);
        dao.register(user,username,password);
        request.getRequestDispatcher("/newlogin.html").forward(request,response);
        session.commit();
        session.close();
    }
}
